home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / wb-tools / colorado / source / colorado.asm < prev    next >
Encoding:
Assembly Source File  |  1995-10-02  |  14.6 KB  |  745 lines

  1.  
  2. TestMode    =    01
  3.  
  4.     IncDir    Includes:
  5.     Include    LVO/DOS_Lib.I
  6.     Include    LVO/Exec_Lib.I
  7.     Include    LVO/Graphics_Lib.I
  8.     Include    LVO/Intuition_Lib.I
  9.  
  10.     BaseReg    BaseReg,a5
  11. ;------------------------------------------------------------
  12.     Section    Colorado,Code_P
  13.  
  14. Start    movem.l    d1-a6,-(sp)
  15.     lea.l    BaseReg,a5
  16.  
  17.     moveq    #36,d0
  18.     lea.l    DOSLib(a5),a1
  19.     move.l    $4.w,a6
  20.     jsr    _LVOOpenLibrary(a6)
  21.     move.l    d0,DOSBase(a5)
  22.     beq.w    End
  23.     moveq    #36,d0
  24.     lea.l    IntuiLib(a5),a1
  25.     jsr    _LVOOpenLibrary(a6)
  26.     move.l    d0,IntuiBase(a5)
  27.     beq.b    CloseAll
  28.     moveq    #36,d0
  29.     lea.l    GfxLib(a5),a1
  30.     jsr    _LVOOpenLibrary(a6)
  31.     move.l    d0,GfxBase(a5)
  32.     beq.b    CloseAll
  33. ;------------------------------------------------------------
  34.     If    TestMode=0
  35. ReadArgs:    move.l    #Template,d1
  36.     move.l    #TmpResult,d2
  37.     moveq    #0,d3
  38.     move.l    DOSBase(a5),a6
  39.     jsr    _LVOReadArgs(a6)
  40.     move.l    d0,TmpID(a5)
  41.     bne.b    .OpenPic
  42.  
  43.     pea    CloseAll
  44.     bra.w    GetIOError
  45.     EndIf
  46. ;------------------------------------------------------------
  47. .OpenPic    bsr.w    OpenILBM        ; And load colormap
  48.     bsr.w    CheckForWBScr    ; And setup colors
  49.     bsr.w    PaletteChange    ; Setup Env:Palette.Prefs
  50.     bsr.w    PatternChange    ; Setup Env:WBPattern.Prefs
  51.  
  52. FreeArgs:    If    TestMode=0
  53.     move.l    TmpID(a5),d1
  54.     move.l    DOSBase(a5),a6
  55.     jsr    _LVOFreeArgs(a6)
  56.     EndIf
  57.  
  58.     bsr.w    PatchOpenScr
  59. ;------------------------------------------------------------
  60. CloseAll:    move.l    PrintErrorTxt,d2
  61.     beq.b    .NoErrors
  62.     bsr.b    PrintText
  63.  
  64. .NoErrors    bsr.b    CloseAllFiles
  65.  
  66.     tst.l    ReturnError(a5)
  67.     bne.b    .Error
  68.  
  69.     If    TestMode=0
  70.     move.l    $4.w,a6
  71.     move.l    #4096,d0
  72.     jsr    _LVOWait(a6)
  73.     move.l    #QuitTxt,d2
  74.     bsr.b    PrintText
  75.     Else
  76.     move.l    IntuiBase(a5),a6
  77.     jsr    _LVOCloseWorkBench(a6)
  78. .Debug    bsr    NewOpenCode
  79.     EndIf
  80.  
  81. .Error    bsr.w    UnPatch
  82.     bsr.b    FreeAllMem
  83.     bsr.b    CloseAllLibs
  84.  
  85. End:    move.l    ReturnError(a5),d0
  86.     movem.l    (sp)+,d1-a6
  87.     rts
  88. ;------------------------------------------------------------
  89. PrintText:    moveq    #0,d3
  90.     move.l    d2,a0
  91. .FindLength    addq    #1,d3
  92.     tst.b    (a0,d3.w)
  93.     bne.b    .FindLength
  94.  
  95. .GetOutput    move.l    DOSBase(a5),a6
  96.     jsr    _LVOOutput(a6)
  97.     move.l    d0,d1
  98.     move.l    DOSBase(a5),a6
  99.     jsr    _LVOWrite(a6)
  100.     rts
  101. ;------------------------------------------------------------
  102. CloseAllFiles:    lea.l    FilesToClose(a5),a3
  103.     lea.l    EndOfFiles(a5),a4
  104.     move.l    DOSBase(a5),a6
  105.  
  106. .FreeLoop    cmp.l    a3,a4
  107.     beq.b    .NoFilesLeft
  108.     move.l    (a3)+,d1
  109.     beq.b    .FreeLoop
  110.     jsr    _LVOClose(a6)
  111.     bra.b    .FreeLoop
  112. .NoFilesLeft    rts
  113. ;------------------------------------------------------------
  114. FreeAllMem:    lea.l    MemToFree(a5),a3
  115.     lea.l    EndOfAlloc(a5),a4
  116.     move.l    $4.w,a6
  117.  
  118. .FreeLoop    cmp.l    a3,a4
  119.     beq.b    .NoMemLeft
  120.     move.l    (a3)+,a1
  121.     move.l    (a3)+,d0
  122.     beq.b    .FreeLoop
  123.     jsr    _LVOFreeMem(a6)
  124.     bra.b    .FreeLoop
  125. .NoMemLeft    rts
  126. ;------------------------------------------------------------
  127. CloseAllLibs:    lea.l    LibsToClose(a5),a3
  128.     lea.l    EndOfLibs(a5),a4
  129.     move.l    $4.w,a6
  130.  
  131. .FreeLoop    cmp.l    a3,a4
  132.     beq.b    .NoLibsLeft
  133.     move.l    (a3)+,a1
  134.     cmp.l    #$00,a1
  135.     beq.b    .FreeLoop
  136.     jsr    _LVOCloseLibrary(a6)
  137.     bra.b    .FreeLoop
  138. .NoLibsLeft    rts
  139. ;------------------------------------------------------------
  140. GetIOError:    move.l    DOSBase(a5),a6
  141.     jsr    _LVOIoErr(a6)
  142.     move.l    d0,d1
  143.  
  144. PrintFault:    move.l    d1,ReturnError(a5)
  145.     move.l    #ProgName,d2
  146.     move.l    DOSBase(a5),a6
  147.     jmp    _LVOPrintFault(a6)
  148. ;------------------------------------------------------------
  149. OpenILBM:    move.l    TmpResult(a5),d1
  150.     move.l    #1005,d2
  151.     move.l    DOSBase(a5),a6
  152.     jsr    _LVOOpen(a6)
  153.     move.l    d0,FileHandle(a5)
  154.     bne.b    .NameFromFH
  155.     move.l    #OpenFailErr,PrintErrorTxt(a5)
  156.     move.l    #CloseAll,(sp)
  157.     bra.b    GetIOError
  158.  
  159. .NameFromFH    move.l    FileHandle(a5),d1
  160.     move.l    #RealName,d2
  161.     move.l    #256,d3
  162.     jsr    _LVONameFromFH(a6)
  163.  
  164. .ReadID    move.l    #12,d3
  165.     bsr.w    Read
  166.  
  167.     cmp.l    #"FORM",HeaderBuffer(a5)
  168.     bne.w    FileTypeError
  169.     cmp.l    #"ILBM",HeaderBuffer+8(a5)
  170.     bne.w    FileTypeError
  171.  
  172. FindCMAP:    moveq    #8,d3
  173.     bsr.w    Read
  174.     cmp.l    #8,d0
  175.     beq.b    .Ok
  176.     move.l    #212,d1
  177.     move.l    #NoCMapErr,PrintErrorTxt(a5)
  178.     bra.w    FileTypeError|.General
  179. .Ok    cmp.l    #"CMAP",HeaderBuffer(a5)
  180.     beq.b    ReadCMAP
  181.     cmp.l    #"BODY",HeaderBuffer(a5)
  182.     bne.b    .NotABody
  183.     st    BodyCheck(a5)
  184. .NotABody    move.l    HeaderBuffer+4(a5),d2
  185.     bsr.w    Seek
  186.     bra.b    FindCMAP
  187.  
  188. ReadCMAP:    move.l    HeaderBuffer+4(a5),d0
  189.     move.l    d0,ColorMapPnt+4(a5)
  190.     moveq    #0,d1
  191.     move.l    $4.w,a6
  192.     jsr    _LVOAllocMem(a6)
  193.     move.l    d0,ColorMapPnt(a5)
  194.     bne.b    .ReadCMAP
  195.     clr.l    ColorMapPnt+4(a5)
  196.     move.l    #103,d1
  197.     move.l    #CloseAll,(sp)
  198.     bra.b    FileTypeError|.General
  199.  
  200. .ReadCMAP    move.l    FileHandle(a5),d1
  201.     move.l    ColorMapPnt(a5),d2
  202.     move.l    ColorMapPnt+4(a5),d3
  203.     move.l    DOSBase(a5),a6
  204.     jsr    _LVORead(a6)
  205.     cmp.l    ColorMapPnt+4(a5),d0
  206.     beq.b    .AllOk
  207.  
  208.     move.l    #219,d1
  209.     move.l    #NoCMapErr,PrintErrorTxt(a5)
  210.     bra.b    FileTypeError|.General
  211.  
  212. .AllOk    tst.b    BodyCheck(a5)
  213.     bne.b    .End
  214. .FindLoop    move.l    #8,d3
  215.     bsr.b    Read
  216.     cmp.l    #8,d0
  217.     bne.b    .End
  218.     cmp.l    #"BODY",HeaderBuffer(a5)
  219.     beq.b    .Found
  220.     move.l    HeaderBuffer+4(a5),d2
  221.     bsr.b    Seek
  222.     bra.b    .FindLoop
  223. .End    rts
  224. .Found    st    BodyCheck(a5)
  225.     bra.b    .End
  226.  
  227. FileTypeError:    move.l    #212,d1
  228.     move.l    #NotIFFErr,PrintErrorTxt(a5)
  229. .General    move.l    #CloseAll,(sp)
  230.     bra.w    PrintFault
  231. ;------------------------------------------------------------
  232. Read:    move.l    FileHandle(a5),d1
  233.     move.l    #HeaderBuffer,d2
  234.     move.l    DOSBase(a5),a6
  235.     jsr    _LVORead(a6)
  236.     rts
  237.  
  238. Seek:    move.l    FileHandle(a5),d1
  239.     moveq    #0,d3
  240.     move.l    DOSBase(a5),a6
  241.     jsr    _LVOSeek(a6)
  242.     rts
  243. ;------------------------------------------------------------
  244. CheckForWBScr:    move.l    IntuiBase(a5),a0
  245.     move.l    60(a0),a1
  246.  
  247. .FindWBScr    cmp.l    #0,a1
  248.     beq.w    .NoOpenWB
  249.  
  250.     move.w    20(a1),d0
  251.     and.b    #$0f,d0
  252.     cmp.b    #$01,d0
  253.     beq.b    .FoundWB
  254.     move.l    (a1),a1
  255.     bra.b    .FindWBScr
  256.  
  257. .FoundWB    lea.l    WBenchName(a5),a0
  258.     move.l    IntuiBase(a5),a6
  259.     jsr    _LVOLockPubScreen(a6)
  260.     move.l    d0,ScreenBase(a5)
  261.  
  262. .GetDepth    move.l    ScreenBase(a5),a0
  263.     move.l    88(a0),a0    ; RastPort->Bitmap
  264.     move.b    5(a0),d2        ; Depth
  265.     moveq    #0,d3
  266.     bset    d2,d3
  267.  
  268.     move.l    ColorMapPnt+4(a5),d2
  269.     divu.w    #3,d2
  270.     move.w    d2,PictureCols(a5)
  271.     move.w    d3,WBScrCols(a5)
  272.     cmp.w    d2,d3
  273.     bge.b    .TstFurther
  274.     move.l    #TooFewColErr,PrintErrorTxt(a5)
  275.     move.w    d3,d7
  276.     sub.w    #4+4+1,d7
  277.     bpl.b    .GetCMap
  278.     bra.b    .UnLockWBScr
  279. .TstFurther    cmp.w    #4,d2
  280.     bls.b    .UnLockWBScr
  281.     cmp.w    #8,d3
  282.     bls.b    .UnLockWBScr
  283.  
  284.     move.w    d2,d7
  285.     subq.w    #1+4,d7
  286.     cmp.w    d2,d3
  287.     bhi.b    .GetCMap
  288.     subq.w    #4,d7
  289.  
  290. .GetCMap    move.l    ScreenBase(a5),a1
  291.     move.l    48(a1),a0
  292.     lea.l    (a0),a2
  293.  
  294. .AttachExPal    lea.l    44(a1),a1
  295.     move.l    GfxBase(a5),a6
  296.     jsr    _LVOAttachPalExtra(a6)
  297.  
  298.     move.l    ColorMapPnt(a5),a3
  299.     lea.l    12(a3),a3
  300.     move.l    GfxBase(a5),a6
  301.     moveq    #0,d4        ; Shared pens
  302.     moveq    #4,d6        ; Col Start number
  303.  
  304. .ColorSetLoop    bsr.b    Precise
  305.     move.l    d0,d1
  306.     bsr.b    Precise
  307.     move.l    d0,d2
  308.     bsr.b    Precise
  309.     move.l    d0,d3
  310.  
  311.     move.l    d6,d0
  312.     lea.l    (a2),a0
  313.     jsr    _LVOObtainPen(a6)
  314.     tst.l    d0
  315.     bpl.b    .Ok
  316.     move.l    d6,d0
  317.     lea.l    (a2),a0
  318.     jsr    _LVOReleasePen(a6)
  319.     subq.w    #3,a3
  320.     bra.b    .ColorSetLoop
  321. .Ok    addq    #1,d6
  322.     dbf    d7,.ColorSetLoop
  323.  
  324. .UnLockWBScr    sub.l    a0,a0
  325.     move.l    ScreenBase(a5),a1
  326.     move.l    IntuiBase(a5),a6
  327.     jsr    _LVOUnlockPubScreen(a6)
  328.  
  329. .NoOpenWB    rts
  330.  
  331. Precise:    move.l    d1,-(sp)
  332.     moveq    #0,d0
  333.     move.b    (a3)+,d0
  334.     move.l    d0,d1
  335.     rol.l    #8,d1
  336.     add.l    d1,d0
  337.     move.w    d0,d1
  338.     swap    d1
  339.     add.l    d1,d0
  340.     move.l    (sp)+,d1
  341.     rts
  342. ;------------------------------------------------------------
  343. PaletteChange:    move.l    #PaletteName,d1
  344.     lea.l    PalPrefPnt(a5),a2
  345.     bsr.w    LoadEnv
  346.     tst.b    d0
  347.     bmi.w    .Error
  348.  
  349.     move.l    PalPrefPnt(a5),a2
  350.     cmp.l    #"PREF",(a2)+
  351.     bne.w    PalError
  352.     cmp.l    #"PRHD",(a2)+
  353.     bne.w    PalError
  354.     add.l    (a2)+,a2
  355.     cmp.l    #"PALT",(a2)+
  356.     bne.w    PalError
  357.     add.l    #4+(4*4)+(32*2)+(32*2),a2
  358.  
  359.     move.l    ColorMapPnt(a5),a3
  360.     moveq    #3,d7
  361. .ColorSetLoop    lea.l    2(a2),a2
  362.     moveq    #2,d6
  363. .CanonSet    moveq    #0,d1
  364.     move.b    (a3),d1
  365.     rol.l    #8,d1
  366.     add.b    (a3)+,d1
  367.     move.w    d1,(a2)+
  368.     dbf    d6,.CanonSet
  369.     dbf    d7,.ColorSetLoop
  370.  
  371. ;    move.w    WBScrCols(a5),d0
  372. ;    cmp.w    PictureCols(a5),d0
  373. ;    bhi    .OpenPalForWrt
  374. ;    sub.w    #4,d0
  375. ;    mulu.w    #3,d0
  376. ;    move.l    ColorMapPnt(a5),a3
  377. ;    add.l    d0,a3
  378.  
  379.     move.l    ColorMapPnt+4(a5),d0
  380.     sub.l    #4*3,d0
  381.     move.l    ColorMapPnt(a5),a3
  382.     add.l    d0,a3
  383.  
  384.     moveq    #3,d7
  385. .ColorSetLoop2    lea.l    2(a2),a2
  386.     moveq    #2,d6
  387. .CanonSet2    moveq    #0,d1
  388.     move.b    (a3),d1
  389.     rol.l    #8,d1
  390.     add.b    (a3)+,d1
  391.     move.w    d1,(a2)+
  392.     dbf    d6,.CanonSet2
  393.     dbf    d7,.ColorSetLoop2
  394.  
  395. .OpenPalForWrt    move.l    #PaletteName,d1
  396.     move.l    #1006,d2
  397.     move.l    DOSBase(a5),a6
  398.     jsr    _LVOOpen(a6)
  399.     move.l    d0,PalHandle(a5)
  400.     bne.b    .WriteHead
  401.     move.l    #NoPal,PrintErrorTxt(a5)
  402.     bra.b    .Error
  403. .WriteHead    move.l    PalHandle(a5),d1
  404.     move.l    #HeaderBuffer,d2
  405.     moveq    #8,d3
  406.     jsr    _LVOWrite(a6)
  407. .WriteRest    move.l    PalHandle(a5),d1
  408.     move.l    PalPrefPnt(a5),d2
  409.     move.l    HeaderBuffer+4(a5),d3
  410.     jsr    _LVOWrite(a6)
  411.  
  412. .Error    rts
  413.  
  414. PalError:    move.l    #212,d1
  415.     move.l    #ErrPal,PrintErrorTxt(a5)
  416.     move.l    #CloseAll,(sp)
  417.     bra.w    PrintFault
  418. ;------------------------------------------------------------
  419. PatternChange:    tst.l    BodyCheck(a5)
  420.     beq.w    .Error
  421.     move.l    #WBPatternName,d1
  422.     lea.l    PtrnPrefPnt(a5),a2
  423.     bsr.w    LoadEnv
  424.     tst.b    d0
  425.     bmi.w    .Error
  426.  
  427.     move.l    HeaderBuffer+4(a5),OldLength
  428.  
  429.     move.l    PtrnPrefPnt(a5),a2
  430.     cmp.l    #"PREF",(a2)+
  431.     bne.w    PtrnError
  432.     cmp.l    #"PRHD",(a2)+
  433.     bne.w    PtrnError
  434.     add.l    (a2)+,a2
  435.     move.l    a2,ChangeHunk(a5)
  436.     cmp.l    #"PTRN",(a2)+
  437.     bne.w    PtrnError
  438.     move.l    (a2)+,d0
  439.  
  440.     btst    #0,d0
  441.     beq    .Even
  442.     addq    #1,d0
  443. .Even
  444.     sub.l    d0,HeaderBuffer+4(a5)
  445.     add.l    a2,d0
  446.     move.l    d0,WBPatFurther(a5)
  447.     add.l    #(4*4),a2
  448.     tst.w    (a2)
  449.     bne.w    PtrnError
  450.  
  451.     lea.l    RealName(a5),a0
  452. .Loop    tst.b    (a0)+
  453.     bne.b    .Loop
  454.     sub.l    #RealName,a0
  455.     move.l    a0,d0
  456.  
  457.     subq    #1,d0
  458.     move.w    d0,PatternStart|.NameLength(a5)
  459.     btst    #0,d0
  460.     beq.b    .Fine
  461.     addq.w    #1,d0
  462. .Fine    move.l    d0,-(sp)
  463.     add.l    d0,PatternStart|.Length(a5)
  464.     move.l    PatternStart|.Length(a5),d0
  465.     add.l    d0,HeaderBuffer+4(a5)
  466.  
  467.     move.l    #WBPatternName,d1
  468.     move.l    #1006,d2
  469.     move.l    DOSBase(a5),a6
  470.     jsr    _LVOOpen(a6)
  471.     move.l    d0,PtrnHandle(a5)
  472.     bne.b    .WriteHead
  473.     move.l    #NoWBP,PrintErrorTxt(a5)
  474.     bra.b    .Error
  475. .WriteHead    move.l    PtrnHandle(a5),d1
  476.     move.l    #HeaderBuffer,d2
  477.     moveq    #8,d3
  478.     jsr    _LVOWrite(a6)
  479.  
  480. .WriteStart    move.l    PtrnHandle(a5),d1
  481.     move.l    PtrnPrefPnt(a5),d2
  482.     move.l    ChangeHunk(a5),d3
  483.     sub.l    d2,d3
  484.     jsr    _LVOWrite(a6)
  485.  
  486. .WriteOwn    move.l    PtrnHandle(a5),d1
  487.     move.l    #PatternStart,d2
  488.     moveq    #8*4,d3
  489.     jsr    _LVOWrite(a6)
  490.  
  491. .WriteName    move.l    PtrnHandle(a5),d1
  492.     move.l    #RealName,d2
  493.     move.l    (sp)+,d3
  494.     jsr    _LVOWrite(a6)
  495.  
  496. .WriteLast    move.l    PtrnHandle(a5),d1
  497.     move.l    WBPatFurther(a5),d2
  498.  
  499.     move.l    OldLength,d3
  500.     move.l    d2,d4
  501.     sub.l    PtrnPrefPnt(a5),d4
  502.     sub.l    d4,d3
  503.     jsr    _LVOWrite(a6)
  504.  
  505. .Error    rts
  506.  
  507. PtrnError:    move.l    #212,d1
  508.     move.l    #ErrWBP,PrintErrorTxt(a5)
  509.     move.l    #CloseAll,(sp)
  510.     bra.w    PrintFault
  511. ;------------------------------------------------------------
  512. LoadEnv:    move.l    #1005,d2
  513.     move.l    DOSBase(a5),a6
  514.     jsr    _LVOOpen(a6)
  515.     move.l    d0,EnvHandle(a5)
  516.     bne.b    .ReadHead
  517.     move.l    #NoEnv,PrintErrorTxt(a5)
  518.     bra.b    .Error
  519.  
  520. .ReadHead    move.l    EnvHandle(a5),d1
  521.     move.l    #HeaderBuffer,d2
  522.     moveq    #8,d3
  523.     jsr    _LVORead(a6)
  524.  
  525. .AllocMem    move.l    HeaderBuffer+4(a5),d0
  526.     move.l    d0,4(a2)
  527.     moveq    #0,d1
  528.     move.l    $4.w,a6
  529.     jsr    _LVOAllocMem(a6)
  530.     move.l    d0,(a2)
  531.     bne.b    .ReadPref
  532.     clr.l    4(a2)
  533.     move.l    #103,d1
  534.     move.l    #CloseAll,4(sp)
  535.     move.l    #PrintFault,(sp)
  536.     bra.b    .Error
  537.  
  538. .ReadPref    move.l    EnvHandle(a5),d1
  539.     move.l    (a2),d2
  540.     move.l    HeaderBuffer+4(a5),d3
  541.     move.l    DOSBase(a5),a6
  542.     jsr    _LVORead(a6)
  543.  
  544. .CloseFile    move.l    EnvHandle(a5),d1
  545.     move.l    DOSBase(a5),a6
  546.     jsr    _LVOClose(a6)
  547.     clr.l    EnvHandle(a5)
  548.  
  549.     moveq    #0,d0
  550.     rts
  551.  
  552. .Error    st    d0
  553.     rts
  554. ;------------------------------------------------------------
  555. PatchOpenScr:    If    TestMode=0
  556.     move.l    #NewOpenCode,d0
  557.     move.l    #_LVOOpenScreenTagList,a0
  558.     move.l    IntuiBase(a5),a1
  559.     move.l    $4.w,a6
  560.     jsr    _LVOForbid(a6)
  561.     jsr    _LVOSetFunction(a6)
  562.     move.l    d0,NewOpenCode|.CallOldCode+2
  563.     jsr    _LVOCacheClearU(a6)
  564.     jsr    _LVOPermit(a6)
  565.     EndIf
  566.     rts
  567. ;------------------------------------------------------------
  568. NewOpenCode:
  569.  
  570.     If    TestMode=0
  571. .CallOldCode    jsr    $0
  572.     Else
  573.     move.l    IntuiBase(a5),a6
  574.     jsr    _LVOOpenWorkBench(a6)
  575.     EndIf
  576.  
  577.     tst.l    d0
  578.     beq.w    .Fail
  579.  
  580.     movem.l    d0-a6,-(sp)
  581.  
  582. .Debug    lea.l    BaseReg,a5
  583.  
  584. .TstWBScr    move.l    (sp),a0
  585.     move.w    20(a0),d0    ; Screen->Flags
  586.     and.w    #$0f,d0
  587.     cmp.w    #$01,d0
  588.     bne.b    .Bummer
  589. .GetDepth    move.l    88(a0),a0    ; RastPort->Bitmap
  590.     move.b    5(a0),d2        ; Depth
  591.     moveq    #0,d3
  592.     bset    d2,d3
  593.  
  594.     move.l    ColorMapPnt+4(a5),d2
  595.     divu.w    #3,d2
  596.     cmp.w    d2,d3
  597.     blo.b    .Bummer
  598.     cmp.w    #4,d2
  599.     bls.b    .Bummer
  600.     cmp.w    #8,d3
  601.     bls.b    .Bummer
  602.  
  603.     move.w    d2,d7
  604.     subq.w    #1+4,d7
  605.     cmp.w    d2,d3
  606.     bhi.b    .GetCMap
  607.     subq.w    #4,d7
  608.  
  609. .GetCMap    move.l    (sp),a1
  610.     move.l    48(a1),a0
  611.     lea.l    (a0),a2
  612. .AttachExPal    lea.l    44(a1),a1
  613.     move.l    GfxBase(a5),a6
  614.     jsr    _LVOAttachPalExtra(a6)
  615.  
  616.     move.l    ColorMapPnt(a5),a3
  617.     lea.l    12(a3),a3
  618.     move.l    GfxBase(a5),a6
  619.     moveq    #0,d4        ; Shared pens
  620.     moveq    #4,d6        ; Col Start number
  621.  
  622. .ColorSetLoop    bsr.w    Precise
  623.     move.l    d0,d1
  624.     bsr.w    Precise
  625.     move.l    d0,d2
  626.     bsr.w    Precise
  627.     move.l    d0,d3
  628.     move.l    d6,d0
  629.     lea.l    (a2),a0
  630.     jsr    _LVOObtainPen(a6)
  631.     addq    #1,d6
  632.     dbf    d7,.ColorSetLoop
  633.  
  634. ;    bsr    PaletteChange
  635.  
  636. .Bummer    movem.l    (sp)+,d0-a6
  637.  
  638. .Fail    rts
  639. ;------------------------------------------------------------
  640. UnPatch:    If    TestMode=0
  641.     move.l    NewOpenCode|.CallOldCode+2,d0
  642.     beq.b    .NoPatch
  643.     move.l    #_LVOOpenScreenTagList,a0
  644.     move.l    IntuiBase(a5),a1
  645.     move.l    $4.w,a6
  646.     jsr    _LVOForbid(a6)
  647.     jsr    _LVOSetFunction(a6)
  648.     jsr    _LVOCacheClearU(a6)
  649.     jsr    _LVOPermit(a6)
  650. .NoPatch    EndIf
  651.     rts
  652. ;------------------------------------------------------------
  653.     Section    Data,Data_P
  654.  
  655. BaseReg:    dc.b    "$VER: Colorado V0.6 (15-Jul-95) Allan Odgaard",0
  656. DOSLib:    dc.b    "dos.library",0
  657. GfxLib:    dc.b    "graphics.library",0
  658. IntuiLib:    dc.b    "intuition.library",0
  659. ProgName:    dc.b    "Colorado",0
  660. WBenchName:    dc.b    "Workbench",0
  661. PaletteName:    dc.b    "Env:Sys/Palette.Prefs",0
  662. WBPatternName:    dc.b    "Env:Sys/WBPattern.Prefs",0
  663. Template:    dc.b    "BackGround/A",0
  664.  
  665.     If    TestMode=1
  666. BackGround:
  667. ;    dc.b    "DH0:Tools/Visual/PPaint_Prefs/MagicRomani.Pal",0
  668. ;    dc.b    "HardDisk:T/WBPic.Green-Dragon",0
  669. ;    dc.b    "HardDisk:T/WBPic.Blue-Dragon",0
  670. ;    dc.b    "HardDisk:T/Trine.MagicWB",0
  671.     dc.b    "HardDisk:T/WBPic.Nude-Girls!",0
  672.     EndIf
  673.  
  674. PalName:    dc.b    "Env:Sys/Palette.Prefs",0
  675. PtrnName:    dc.b    "Env:Sys/WBPattern.Prefs",0
  676.  
  677. OpenFailErr:    dc.b    "Couldn't open the specified background picture",10,0
  678. NotIFFErr:    dc.b    "The specified background picture is not IFF/ILBM",10,"Or has an error in its format",10,0
  679. NoCMapErr:    dc.b    "The file contains no colormap specifications",10,0
  680. TooFewColErr:    dc.b    "The image has more colors than your WorkBench",10,0
  681. NoEnv:    dc.b    "Couldn't open Env:Sys/(Palette|WBPattern).Prefs",10,0
  682. NoPal:    dc.b    "Couldn't modify Env:Sys/(Palette.Prefs",10,0
  683. NoWBP:    dc.b    "Couldn't modify Env:Sys/WBPattern.Prefs",10,0
  684. ErrPal:    dc.b    "Env:Sys/Palette.Prefs seems to be smashed",10,0
  685. ErrWBP:    dc.b    "Env:Sys/WBPattern.Prefs seems to be smashed",10,0
  686. QuitTxt:    dc.b    "Ups... You just quited Colorado!",10,0
  687.  
  688.     Even
  689.  
  690. PatternStart:    dc.b    "PTRN"
  691. .Length    dc.l    6*4
  692.     dcb.l    4
  693. .Which    dc.w    $0000
  694. .Flags    dc.w    $0010
  695. .Revision    dc.b    0
  696. .Depth    dc.b    0
  697. .NameLength    dc.w    0
  698.  
  699.     If    TestMode=1
  700. TmpResult:    dc.l    BackGround
  701.     Else
  702. TmpResult:    ds.l    1
  703.     EndIf
  704.  
  705. LibsToClose:
  706. DOSBase:    ds.l    1
  707. GfxBase:    ds.l    1
  708. IntuiBase:    ds.l    1
  709. EndOfLibs:
  710.  
  711. FilesToClose:
  712. FileHandle:    ds.l    1
  713. EnvHandle:    ds.l    1
  714. PtrnHandle:    ds.l    1
  715. PalHandle:    ds.l    1
  716. EndOfFiles:
  717.  
  718. MemToFree:
  719. ColorMapPnt:    ds.l    2
  720. PtrnPrefPnt:    ds.l    2
  721. PalPrefPnt:    ds.l    2
  722. EndOfAlloc:
  723.  
  724. PictureCols:    ds.w    1
  725. WBScrCols:    ds.w    1
  726. TmpID:    ds.l    1
  727. OldOpenScr:    ds.l    1
  728. ScreenBase:    ds.l    1
  729. DrawInfo;    ds.l    1
  730. ColorMap:    ds.l    1
  731. ChangeHunk:    ds.l    1
  732. WBPatFurther:    ds.l    1
  733. OldLength:    ds.l    1
  734.  
  735. BodyCheck:    ds.l    1
  736.  
  737. HeaderBuffer:    ds.l    3    ; FORM lngh ILBM
  738.  
  739. PrintErrorTxt:    ds.l    1
  740. ReturnError:    ds.l    1
  741.  
  742. WBTags:    ds.l    25
  743. RealName:    ds.b    256
  744.  
  745. ž-k-ˆ"J»